package com.wjh.anyview.controller;

import com.wjh.anyview.entity.bo.userServiceBo.LoginBo;
import com.wjh.anyview.entity.bo.userServiceBo.UserLoginBo;
import com.wjh.anyview.entity.dto.CommonResult;
import com.wjh.anyview.entity.po.User;
import com.wjh.anyview.entity.vo.userControllerVo.InvigilatorVo;
import com.wjh.anyview.service.UserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wjh
 * @date 2021/10/9 18:10
 * @Package com.wjh.anyview.controller
 */
@RestController
@RequestMapping("/api/user")
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping("/login")
    public CommonResult<UserLoginBo> login(@RequestBody LoginBo loginBo) {
        return userService.login(loginBo);
    }

    @PostMapping("/saveStudent")
    @PreAuthorize("hasAuthority('/saveStudent')")
    public CommonResult<?> saveStudent(@RequestBody User user) {
        return userService.saveStudent(user);
    }

    @RequestMapping("/getGradeByNum")
    @PreAuthorize("hasAuthority('/getGradeByNum')")
    public CommonResult<Byte> getGradeByNum(@RequestParam("num") String num) {
        return userService.getGradeByNum(num);
    }

    @RequestMapping("/listInvigilatorByInstitutionId")
    @PreAuthorize("hasAuthority('/listInvigilatorByInstitutionId')")
    public CommonResult<List<InvigilatorVo>> listInvigilatorByInstitutionId(@RequestParam("institutionId") Long institutionId){
        return userService.listInvigilatorByInstitutionId(institutionId);
    }
}
